<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    function get(url) {
      // 要使用.then方法，那么必须返回出去一个promise对象
      return new Promise((resolve, rejesct) => {
        let oReq = new XMLHttpRequest();
        oReq.onload = function () {
          // 现在需要得到这里的 oReq.responseText
          resolve(JSON.parse(oReq.responseText));
        }
        oReq.onerror = function (err) {
          rejesct(err);
        }
        oReq.open("get", url, true);
        oReq.send();
      })
    }

    // 网上随便找了一个新闻接口
    get('http://route.showapi.com/109-35?showapi_appid=65105&&showapi_sign=7ba716e8d1de4363b7745b6e63b442fc')
      .then(function (data) {
        console.log(data);
      }, function (err) {
        console.log(err);
      })
  </script>
</body>

</html>